//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

import { fetch } from '@tauri-apps/plugin-http';

export interface AtomGitOrg {
    login: string;
    id: string;
    url: string;
    repos_url: string;
    events_url: string;
    hooks_url: string;
    issues_url: string;
    members_url: string;
    public_members_url: string;
    avatar_url: string;
    description: string;
}

export async function list_user_org(accessToken: string): Promise<AtomGitOrg[]> {
    const headers = [["Origin", ""], ["Authorization", `Bearer ${accessToken}`]] as [string, string][]; //fix http with unsafe-header return 403
    const res = await fetch(`https://api.atomgit.com/user/orgs`, {
        method: "GET",
        headers: headers,
    });
    if (res.ok && res.status == 200) {
        return await res.json();
    } else {
        console.log(res);
        throw "error list org";
    }
}